package com.hospital.drug.drugyan.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hospital.drug.drugyan.dao.DoctorMapper;
import com.hospital.drug.drugyan.dao.DutyMapper;
import com.hospital.drug.drugyan.dao.ResMapper;
import com.hospital.drug.drugyan.entity.Doctor_falls;
import com.hospital.drug.drugyan.entity.Doctor_information;
import com.hospital.drug.drugyan.entity.Resignation_Form;
import com.hospital.drug.drugyan.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 波——最帅的男人
 * @version 1.0
 * @date 2021/5/13 16:11
 */

@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;
    @Autowired
    private ResMapper resMapper;

    @Autowired
    private DutyMapper dutyMapper;

    /**
     * 分布查询医生
     *
     * @param pageNum
     * @param name
     * @return
     */
    @Override
    public PageInfo<Doctor_information> pageListDoctor(Integer pageNum, String name) {
        PageHelper.startPage(pageNum, 5);
        List<Doctor_information> doctor_informations = null;
        if (name != null && !name.equals("")) {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.like("doctorname", name);
            doctor_informations = doctorMapper.selectList(queryWrapper);
        } else {
            doctor_informations = doctorMapper.selectList(null);
        }
        PageInfo<Doctor_information> pageInfo = new PageInfo<>(doctor_informations);
        return pageInfo;
    }

    /**
     * 医生插入
     *
     * @param doctor_information
     * @return
     */
    @Override
    public boolean insertDoctor(Doctor_information doctor_information) {
        int i = doctorMapper.insert(doctor_information);
        if (i == 1) {
            return true;
        }
        return false;
    }

    /**
     * 医生删除
     *
     * @param id
     * @return
     */
    @Override
    public boolean deleteDoctor(Integer id) {
        Doctor_information doctor_information = resMapper.selRes(id);
        int i1 = resMapper.insRes(doctor_information);
        int i = doctorMapper.deleteById(id);
        if (i == 1 && i1==1) {
            return true;
        }
        return false;
    }

    /**
     * 更新医生信息
     *
     * @param doctor_information
     * @return
     */
    @Override
    public boolean updateDoctor(Doctor_information doctor_information) {
        int count = doctorMapper.updateById(doctor_information);
        if (count == 1) {
            return true;
        }
        return false;
    }

    @Override
    public boolean insertDuty(Doctor_falls doctor_falls) {
        int insert = dutyMapper.insertDuty(doctor_falls);
        if (insert==1){
            return true;
        }
        return false;
    }

    @Override
    public List<Resignation_Form> selectRes() {
        List<Resignation_Form> resignation_forms = resMapper.selectRes();
        System.out.println(resignation_forms);
        return resignation_forms;
    }


}
